var app = getApp();
var config = require('../../../config.js');
var util = require('../../../js/common.util.js');
Page({
  data: {
    array: ['已引荐', '已签单'],
    index: 0,
    id: '',
    isEdit:0,
    remark:'',
    detailInfo: {}
  },
  bindPickerChange(e) {
    this.setData({
      index: e.detail.value
    })
    console.log(this.data.index)
  },
  remarkInput(e){
    this.setData({
      remark: e.detail.value
    })
  },
  onShareAppMessage: function () {

  },
  submit(){
    //引荐
    let self = this
    var url = ''
    var txt = '已引荐'
    if (this.data.array.length == 2){
      if (this.data.index == 0) {
        url = 'api/wechat/DoAwait'
        //已签单
      } else if (this.data.index == 1) {
        txt = '已签单'
        url = 'api/wechat/DoSign'
      }
    }else{ //等于1 length  那就是已引荐没通过 过来的 直接走已签单
      txt = '已签单'
      url = 'api/wechat/DoSign'
    }

    wx.showModal({
      title: '提示',
      content: '您确定要将状态修改为 ' +txt+ ' 吗？',
      success: function (sm) {
        if (sm.confirm) {
          self.doit(url)
        } else if (sm.cancel) {
        }
      }
    })
  },
  doit(url){
    let self = this
    app.request({
      url: url,
      method: "GET",
      data: {
        id: self.data.id,
        remark:self.data.remark
      },
      success: function (res) {
          wx.redirectTo({
            url: '/page/BusinessCenter/changesState/index'
          })
      }
    })
  },
  onLoad: function (options) {
    this.loadDetail(options.id)
    this.setData({
      id: options.id,
      isEdit: options.isEdit
    })
  },
  loadDetail(id) {
    let self = this
    app.request({
      url: 'api/wechat/GetBusinessById',
      method: "GET",
      data: {
        id: id
      },
      success: function (res) {
        console.log(res)
        if (res != null && res.data != null && res.data.info != null) {
          if (res.data.info.passTime != null) {
            res.data.info.passTime = util.formatTime(res.data.info.passTime)
          }
          res.data.info.createTime = util.formatTime(res.data.info.createTime)
          if (res.data.info.rejectTime != null) {
            res.data.info.rejectTime = util.formatTime(res.data.info.rejectTime)
          }
          //已引荐 没通过呢
          if (res.data.info.businessStatus == 4 || res.data.info.businessStatus == 5){
            //只可选 已签单 改成已签单 没有别的操作
            self.setData({
              array:['已签单']
            })
          }else{
            //其他正常
          }
          self.setData({
            detailInfo: res.data.info,
          })
        }
      }
    })
  }
})